//
//  NSDate+Helper.h
//

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

/**
 calendar 日历
 timeZone 时区
 era 时代
 year 年
 month 月
 day 日
 hour 时
 minute 分
 second 秒
 nanosecond 纳秒
 weekday 一周的第几天，通常从周日开始为1，即周三为4。
 weekdayOrdinal 本月的第几个weekday。若weekday为周三，表示为本月的第几个周三，若本月是周四为1号，那么周三则是在上个月，虽然今天是第3周，但此处则为2。
 quarter 季度，0-3 ，0表示12月1月2月。
 weekOfMonth 本月第几周
 weekOfYear 本年第几周
 yearForWeekOfYear ISO8601标准下的年份。该标准一年有52或53周，在最后一周时，可能会出现该周属于2020年，但在ISO8601标准，该周属于2021年。
 */

@interface NSDate (Helper)

+ (NSDate*)dateFromString:(NSString*)string withFormat:(NSString*)format;
+ (NSDate*)dateFromSQLDateString:(NSString*)string;
+ (NSDate*)dateFromTimeStamp:(NSTimeInterval)timeStamp;
+ (NSDate*)dateWithYear:(NSInteger)year month:(NSInteger)month day:(NSInteger)day;
+ (NSDate*)dateWithYear:(NSInteger)year month:(NSInteger)month day:(NSInteger)day hour:(NSInteger)hour minute:(NSInteger)minute second:(NSInteger)second;
+ (NSDate*)dateWithYear:(NSInteger)year month:(NSInteger)month day:(NSInteger)day
                   hour:(NSInteger)hour minute:(NSInteger)minute second:(NSInteger)second nanosecond:(NSInteger)nanosecond;

+ (BOOL)timeStampIsToday:(NSTimeInterval)timeStamp;
+ (BOOL)timeStampIsSameDay:(NSTimeInterval)timeStamp timeStamp2:(NSTimeInterval)timeStamp2;
+ (BOOL)stringIsToday:(NSString*)string withFormat:(NSString*)format;
+ (BOOL)stringIsSameDay:(NSString*)string string2:(NSString*)string2 withFormat:(NSString*)format;
+ (BOOL)stringIsSameDay:(NSString*)string withFromat:(NSString*)format string2:(NSString*)string2 withFormat2:(NSString*)format2;

+ (NSString*)dateStringFromString:(NSString*)string format:(NSString*)format toFormat:(NSString*)toFromat;
+ (NSString*)dateStringWithTimeStamp:(NSTimeInterval)timeStamp withFormat:(NSString*)format;
+ (NSString*)sqlDateStringWithTimeStamp:(NSTimeInterval)timeStamp;
+ (NSString*)nanosecondDateStringWithTimeStamp:(NSTimeInterval)timeStamp;

- (NSString*)stringWithFormat:(NSString*)format;
- (NSString*)stringWithNanosecond;
- (NSString*)stringWithSQLDateFormat;

- (NSTimeInterval)timeStamp;

- (BOOL)isLeapYear;

- (NSInteger)era;
- (NSInteger)year;
- (NSInteger)month;
- (NSInteger)day;
- (NSInteger)hour;
- (NSInteger)minute;
- (NSInteger)second;
- (NSInteger)nanosecond;
- (NSInteger)weekday;
- (NSInteger)weekdayOrdinal;
- (NSInteger)quarter;
- (NSInteger)weekOfMonth;
- (NSInteger)weekOfYear;
- (NSInteger)yearForWeekOfYear;
- (NSUInteger)daysInMonth;
- (NSUInteger)daysInYear;
- (NSUInteger)dayOfYear;

// 农历
- (NSString *)chineseYear;
- (NSString *)chineseMonth;
- (NSString *)chineseDay;

- (NSString*)chineseFullWeekdayName;    // 星期几
- (NSString*)chineseShortWeekdayName;   // 周几

// 范围
- (NSDate*)beginOfYear;
- (NSDate*)endOfYear;
- (NSDate*)beginOfMonth;
- (NSDate*)endOfMonth;
- (NSDate*)beginOfWeek;
- (NSDate*)endOfWeek;
- (NSDate*)beginOfDay;
- (NSDate*)endOfDay;

// 是否同一天，不计时分秒
- (BOOL)isSameDay:(NSDate*)date;
- (BOOL)isSameDayWithDateString:(NSString*)string withFormat:(NSString*)format;

- (BOOL)isToday;
- (BOOL)isYesterday;
- (BOOL)isTomorrow;
- (BOOL)isWeekend;

// 星期
- (BOOL)isSunday;
- (BOOL)isMonday;
- (BOOL)isTuesday;
- (BOOL)isWednesday;
- (BOOL)isThurday;
- (BOOL)isFriday;
- (BOOL)isSaturday;

// 距离date
- (NSInteger)yearsFrom:(NSDate*)date;
- (NSInteger)monthsFrom:(NSDate*)date;
- (NSInteger)weeksFrom:(NSDate*)date;
- (NSInteger)daysFrom:(NSDate*)date;
- (double)hoursFrom:(NSDate*)date;
- (double)minutesFrom:(NSDate*)date;
- (double)secondsFrom:(NSDate*)date;

// 将来距离今天 <= [NSDate date] 则返回 0
-(NSInteger)yearsUntil;
-(NSInteger)monthsUntil;
-(NSInteger)weeksUntil;
-(NSInteger)daysUntil;
-(double)hoursUntil;
-(double)minutesUntil;
-(double)secondsUntil;

// 过去距离今天 >= [NSDate date] 则返回 0
-(NSInteger)yearsAgo;
-(NSInteger)monthsAgo;
-(NSInteger)weeksAgo;
-(NSInteger)daysAgo;
-(double)hoursAgo;
-(double)minutesAgo;
-(double)secondsAgo;

// 早 >= date 则返回 0
- (NSInteger)yearsEarlierThan:(NSDate*)date;
- (NSInteger)monthsEarlierThan:(NSDate*)date;
- (NSInteger)weeksEarlierThan:(NSDate*)date;
- (NSInteger)daysEarlierThan:(NSDate*)date;
- (double)hoursEarlierThan:(NSDate*)date;
- (double)minutesEarlierThan:(NSDate*)date;
- (double)secondsEarlierThan:(NSDate*)date;

// 晚 <= date 则返回 0
- (NSInteger)yearsLaterThan:(NSDate*)date;
- (NSInteger)monthsLaterThan:(NSDate*)date;
- (NSInteger)weeksLaterThan:(NSDate*)date;
- (NSInteger)daysLaterThan:(NSDate*)date;
- (double)hoursLaterThan:(NSDate*)date;
- (double)minutesLaterThan:(NSDate*)date;
- (double)secondsLaterThan:(NSDate*)date;

// 比较
- (BOOL)isEarlierThan:(NSDate*)date;
- (BOOL)isLaterThan:(NSDate*)date;
- (BOOL)isEarlierThanOrEqualTo:(NSDate*)date;
- (BOOL)isLaterThanOrEqualTo:(NSDate*)date;
- (BOOL)isBetween:(NSDate*)date date2:(NSDate*)date2;

// 加
- (NSDate*)addingYears:(NSInteger)years;
- (NSDate*)addingMonths:(NSInteger)months;
- (NSDate*)addingDays:(NSInteger)days;
- (NSDate*)addingWeeks:(NSInteger)weeks;
- (NSDate*)addingHours:(NSInteger)hours;
- (NSDate*)addingMinutes:(NSInteger)minutes;
- (NSDate*)addingSeconds:(NSInteger)seconds;
- (NSDate*)addingNanoSeconds:(NSInteger)nanoseconds;
- (NSDate*)addingYears:(NSInteger)years months:(NSInteger)months days:(NSInteger)days
              hours:(NSInteger)hours minutes:(NSInteger)minutes seconds:(NSInteger)seconds nanoseconds:(NSInteger)nanoseconds;

// 减
- (NSDate*)subtractingYears:(NSInteger)years;
- (NSDate*)subtractingMonths:(NSInteger)months;
- (NSDate*)subtractingWeeks:(NSInteger)weeks;
- (NSDate*)subtractingDays:(NSInteger)days;
- (NSDate*)subtractingHours:(NSInteger)hours;
- (NSDate*)subtractingMinutes:(NSInteger)minutes;
- (NSDate*)subtractingSeconds:(NSInteger)seconds;
- (NSDate*)subtractingNanoseconds:(NSInteger)nanosecond;
- (NSDate*)subtractingYears:(NSInteger)years months:(NSInteger)months days:(NSInteger)days
                      hours:(NSInteger)hours minutes:(NSInteger)minutes seconds:(NSInteger)seconds nanoseconds:(NSInteger)nanoseconds;
@end

NS_ASSUME_NONNULL_END
